package com.ouheng.shop.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ouheng.shop.dao.CouponDao;
import com.ouheng.shop.domain.CouponDO;
import com.ouheng.shop.domain.PremiumDO;
import com.ouheng.shop.domain.ProductPriceDO;
import com.ouheng.shop.service.CouponService;



@Service
public class CouponServiceImpl implements CouponService {
	@Autowired
	private CouponDao couponDao;
	
	@Override
	public CouponDO get(Long id){
		return couponDao.get(id);
	}
	
	@Override
	public List<CouponDO> list(Map<String, Object> map){
		return couponDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return couponDao.count(map);
	}
	
	@Override
	@Transactional
	public int save(CouponDO coupon){
//		List<CouponDO> listCoupon = couponDao.list(null);
//		if(listCoupon.isEmpty()){
//			coupon.setStatus("2");
//		}else{
//			if("2".equals(coupon.getStatus())){
//				Map<String, Object> map = new HashMap<>();
//				map.put("status", 2);
//				List<CouponDO> listCouponDO = couponDao.list(map);
//				for (CouponDO couponDO : listCouponDO) {
//					couponDO.setStatus("1");
//					couponDao.update(couponDO);
//				}
//			}
//		}
		return couponDao.save(coupon);
	}
	
	@Override
	@Transactional
	public int update(CouponDO coupon){
//		if("2".equals(coupon.getStatus())){
//			Map<String, Object> map = new HashMap<>();
//			map.put("status", 2);
//			List<CouponDO> list = couponDao.list(map);
//			if(!list.isEmpty()){
//				for (CouponDO couponDO : list) {
//					couponDO.setStatus("1");
//					couponDao.update(couponDO);
//				}
//			}
//		}
		return couponDao.update(coupon);
	}
	
	@Override
	@Transactional
	public int remove(Long id){
		return couponDao.remove(id);
	}
	
	@Override
	@Transactional
	public int batchRemove(Long[] ids){
		return couponDao.batchRemove(ids);
	}
	
}
